//
//  MineVC.m
//  jzyStudents
//
//  Created by 任辰东 on 2022/9/21.
//

#import "MineVC.h"
#import "RCDBaseLayoutView.h"
#import "UserInfoView.h"
#import "MineCustomBtn.h"
#import "LoginVC.h"
#import "SetupVC.h"
#import "AboutVC.h"
#import "RCDGroupBtnsView.h"
#import "RCDWebViewController.h"

#import "AvatarView.h"
#import "RCDGroupBtnsView.h"
#import "AboutVC.h"
#import "RCDWebViewController.h"
#import "SetupVC.h"
#import "UserInfoVC.h"
#import "RCDTextFeidView.h"
#import "MineApis.h"
#import "EduExperienceListVC.h"


@interface MineVC ()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) AvatarView *avatarView;
@property (nonatomic, strong) UILabel *markLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *infoLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UIControl *arrowTouView;

@property (nonatomic, strong) UserInfoModel *model;
@end

@implementation MineVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"我的";
    
    [self.avatarView configViewWithName:[GVUserDefaults standardUserDefaults].student_name Avatar:@""];
    self.nameLabel.hidden = NO;
    self.infoLabel.hidden = NO;
    self.markLabel.hidden = YES;
    self.nameLabel.text = [NSString stringWithFormat:@"%@   ID:%@",[GVUserDefaults standardUserDefaults].student_name,[GVUserDefaults standardUserDefaults].student_id];
    NSString *organName = IsEmpty([GVUserDefaults standardUserDefaults].organ_name) ? @"暂无学校":[GVUserDefaults standardUserDefaults].organ_name;
    NSString *className = IsEmpty([GVUserDefaults standardUserDefaults].class_name) ? @"暂无班级":[GVUserDefaults standardUserDefaults].class_name;

    self.infoLabel.text = [NSString stringWithFormat:@"%@   %@ ",organName,className];
}

- (void)arrowTouViewAction
{
    UserInfoVC *infoVC = [[UserInfoVC alloc]init];
    [self.navigationController pushViewController:infoVC animated:YES];
}

-(void)setupViews
{
    [self.bgScrollView.contentView addSubview:self.topView];
    [self.topView addSubview:self.avatarView];
    [self.topView addSubview:self.markLabel];
    [self.topView addSubview:self.nameLabel];
    [self.topView addSubview:self.iconImageView];
    [self.topView addSubview:self.infoLabel];
    [self.topView addSubview:self.arrowImageView];
    [self.topView addSubview:self.arrowTouView];
    
    NSArray *titleArr = @[@"教育信息",@"设置",@"隐私政策",@"用户协议",@"举报",@"关于"];
    NSArray *iconArr = @[@"mine_dangan",@"mine_shezhi",@"mine_yinsi",@"mine_xieyi",@"mine_jubao",@"mine_guanyu"];
    
    RCDTextFeidView *bufferView;
    for (NSInteger i = 0; i < titleArr.count; i ++) {
        
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftImgPath = iconArr[i];
        model.leftTitle = titleArr[i];
        model.leftTitleColor = UIColorFromHex(kColorTitle);
        model.leftTitleFont = UIFontSize(15);
        model.rightImgPath = @"arrow";
        RCDTextFeidView *tagView = [[RCDTextFeidView alloc]initWithModel:model];
        tagView.backgroundColor = UIColorFromHex(kColorWhite);
        tagView.tag = 200 + i;
        [self.bgScrollView.contentView addSubview:tagView];
        [tagView setTouchDownTarget:self action:@selector(tagViewAction:)];
        
        if (i  == titleArr.count - 1 || i  == 1) {
            [tagView addBottomLine];
        }else{
            [tagView addBottomLineWithEdge:UIEdgeInsetsMake(0, 15, 0, 15)];
        }
        
        if (i == 0 || i == 1) {
            [tagView addTopLine];
        }
        
        [tagView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            if (!bufferView) {
                make.top.equalTo(self.topView.mas_bottom).offset(10);
            }else{
                
                if (i == 1) {
                    make.top.equalTo(bufferView.mas_bottom).offset(10);
                }else{
                    make.top.equalTo(bufferView.mas_bottom).offset(0);
                }
            }
            
            make.left.right.equalTo(self.bgScrollView.contentView);
            make.height.mas_equalTo(50);
            
            if (i == titleArr.count -1) {
                make.bottom.equalTo(self.bgScrollView.contentView).offset(kBottomOffset);
            }
            
        }];
        bufferView = tagView;
    }
    
    [self.arrowTouView addTarget:self action:@selector(arrowTouViewAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)tagViewAction:(RCDTextFeidView *)tagView
{
    switch (tagView.tag) {
        case 200:
        {
//            DLog(@"教育经历");
            EduExperienceListVC *eduVC = [EduExperienceListVC new];
            [self.navigationController pushViewController:eduVC animated:YES];
        }
            break;
        case 201:
        {
            //设置
            SetupVC *setupVC = [SetupVC new];
            [self.navigationController pushViewController:setupVC animated:YES];
        }
            break;
        case 202:
        {
            RCDWebViewController *webVC = [[RCDWebViewController alloc]initWithUrl:kPrivacyPolicyUrl];
            webVC.navigationItem.title = @"隐私政策";
            [self.navigationController pushViewController:webVC animated:YES];
        }
            break;
        case 203:
        {
            RCDWebViewController *webVC = [[RCDWebViewController alloc]initWithUrl:kUserAgreementUrl];
            webVC.navigationItem.title = @"用户协议";
            [self.navigationController pushViewController:webVC animated:YES];
        }
            break;
        case 204:
        {
            //举报
            RCDWebViewController *webVC = [[RCDWebViewController alloc]initWithUrl:@"https://www.12377.cn"];
            [self.navigationController pushViewController:webVC animated:YES];
        }
            break;
        case 205:
        {
            //关于
            AboutVC *aboutVC = [AboutVC new];
            [self.navigationController pushViewController:aboutVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}

- (void)getData
{
//    WeakSelf
//    
//    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    params[@"mobile"] = [GVUserDefaults standardUserDefaults].mobile;
//    params[@"student_id"] = [UserInfoManager sharedInstance].studentInfo.student_id;
//
//    [MineApis getjiazhangmsgRequestWithParams:params SuccessBlock:^(NSNumber *code, NSString *msg, id responseData) {
//        StrongSelf
//        [self hideLoadingHUD];
//        UserInfoModel *model = [UserInfoModel mj_objectWithKeyValues:responseData];
//        self.model = model;
//        [self.avatarView configViewWithName:model.student_name Avatar:@""];
//        self.nameLabel.hidden = NO;
//        self.infoLabel.hidden = NO;
//        self.markLabel.hidden = YES;
//        self.nameLabel.text = [NSString stringWithFormat:@"%@%@   ID%@",model.student_name,model.guanxi,model.parent_id];
//        
//        self.iconImageView.hidden = !model.is_zhu.boolValue;
//        
//        NSString *organName = IsEmpty(model.organ_name) ? @"暂无学校":model.organ_name;
//        NSString *className = IsEmpty(model.class_name) ? @"暂无班级":model.class_name;
//        
//        self.infoLabel.text = [NSString stringWithFormat:@"%@   %@ ",organName,className];
//        
//        UserInfoModel *userModel = [UserInfoManager sharedInstance].userInfo;
//        model.stu_list = userModel.stu_list;
//        [UserInfoManager sharedInstance].userInfo = model;
//        [JzyTools cachesUserInfo:model];
//        
//        } FailureBlock:^(NSNumber *code, NSString *msg) {
//        StrongSelf
//            [self showWarningHUDWithMessage:msg completion:NULL];
//        }];
}


-(void)setupLayout
{
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.left.right.equalTo(self.bgScrollView.contentView);

    }];

    [self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.topView).offset(30);
        make.left.equalTo(self.topView).offset(kPaddingLeft);
        make.bottom.equalTo(self.topView).offset(-30);
        make.height.width.mas_equalTo(50);
    }];

    [self.markLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.avatarView);
        make.left.equalTo(self.avatarView.mas_right).offset(kPaddingLeft);
        make.right.equalTo(self.topView).offset(kPaddingRight);
    }];

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.avatarView).offset(5);
        make.left.equalTo(self.avatarView.mas_right).offset(10);
//        make.right.equalTo(self.topView).offset(-30);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.nameLabel.mas_centerY).offset(0);
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(41);
    }];

    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.equalTo(self.avatarView.mas_bottom).offset(-5);
        make.left.equalTo(self.avatarView.mas_right).offset(10);
        make.right.equalTo(self.topView).offset(-30);
    }];

    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.topView);
        make.right.equalTo(self.topView).offset(kPaddingRight);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(9);
    }];
    
    
    [self.arrowTouView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.right.bottom.equalTo(self.topView);
        make.width.mas_equalTo(kScreenWidth);
    }];
}

#pragma mark -- lazyload

-(UIView *)topView
{
    if (!_topView) {
        _topView = [UIView new];
        _topView.backgroundColor = UIColorFromHex(kColorWhite);
        [_topView addBottomLine];
    }
    return _topView;
}

-(AvatarView *)avatarView
{
    if (!_avatarView) {
        _avatarView = [[AvatarView alloc]initWithPlaceholderImage:UIImageWithName(@"mine_avatar")];
    }
    return _avatarView;
}

-(UIImageView *)arrowImageView
{
    if (!_arrowImageView) {
        _arrowImageView = [UIImageView new];
        _arrowImageView.image = UIImageWithName(@"arrow");
        _arrowImageView.contentMode = UIViewContentModeScaleToFill;
        _arrowImageView.clipsToBounds = YES;
    }
    return _arrowImageView;
}

-(UILabel *)markLabel
{
    if (!_markLabel) {
        _markLabel = [UILabel new];
        _markLabel.text = @"未绑定";
        _markLabel.textColor = UIColorFromHex(kColorTitle);
        _markLabel.font = UIFontSize(15);
    }
    return _markLabel;
}

-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.text = @"   ";
        _nameLabel.textColor = UIColorFromHex(0x000000);
        _nameLabel.font = UIFontSize(15);
    }
    return _nameLabel;
}

-(UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [UIImageView new];
        _iconImageView.image = UIImageWithName(@"user_mark");
        _iconImageView.contentMode = UIViewContentModeScaleToFill;
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UILabel *)infoLabel
{
    if (!_infoLabel) {
        _infoLabel = [UILabel new];
        _infoLabel.text = @"   ";
        _infoLabel.textColor = UIColorFromHex(kColorPlaceholder);
        _infoLabel.font = UIFontSize(13);
    }
    return _infoLabel;
}

-(UIControl *)arrowTouView
{
    if (!_arrowTouView) {
        _arrowTouView = [UIControl new];
        _arrowTouView.backgroundColor = [UIColor clearColor];
    }
    return _arrowTouView;
}
@end
